#ifndef BODY_H
#define BODY_H

#include <GL/glew.h>
#include <GL/glut.h>
#include "Particle.h"

class Body {
protected:
	static int count;
	float color[3];

	float mass;
	float force[3];
	float position[3];
	float velocity[3];
	float linearMomentum[3];
	float terminalMomentum;

	float quaternion[4];
	float rotationMatrix[9];
	float angularVelocity[3];
	float angularMomentum[3];

	float initialInverseInertiaTensorDiagonal[3];
	float inverseInertiaTensor[9];

	int numberOfParticles;
	Particle** particles;

	void performLinearStep(float delta);
	void performAngularStep(float delta);
	void updateRotationMatrix();
	void normalizeQuaternion();
	virtual void applyRotationToParticles() {};
	virtual void updateInverseInertiaTensor() {};
public:
	Body();
	void performStep(float delta);
	virtual void createParticles() {};

	void updateParticleValues();
	void updateMomenta(float delta);
	

	virtual void updateVBO(int vertexIndex) {};
	virtual void updateColorArray(int vertexIndex) {};
	void updateParticleVBO(int vertexIndex);
	void updateParticleColorArray(int vertexIndex);

	void populateParticleArray();
	void reset(float* newPosition);
};
#endif
